﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StringFormattingEncoding
{
    class Functionality
    {
        static void PrintStringInHexBytes(string input)
        {
            byte[] bytes = Encoding.Default.GetBytes(input);
            foreach (byte b in bytes)
            {
                Console.Write("\\x{0:X}", b);
            }
            Console.WriteLine();
        }

        static void PrintNumbers5to25()
        {
            for (int i = 5; i <= 25; i++)
            {
                Console.Write("{0,5} {1,-6} {2,10:0.0000} {3}",i, i*i, Math.Sqrt(i), Math.Log(i));
                Console.WriteLine();
            }
        }

        static void ParseDate(string input)
        {
            DateTime date;
            string[] formats = { "dd.MM.yyyy", "dd/MM/yyyy", "dd.MM.yy", "dd/MM/yy" };
            date = DateTime.ParseExact(input, formats, null, System.Globalization.DateTimeStyles.None);
            Console.WriteLine("Day={0}, Month={1}, Year={2}", date.Day, date.Month, date.Year);
        }

        static void PrintCurrencies(double amount)
        {
            string[] formats = { "de-AT", "bg-BG", "he-IL", "mn-MN", "th-TH", "ja-JP" };
            StringBuilder message = new StringBuilder("");
            foreach (string format in formats)
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(format);
                string str = string.Format("{0:C}", amount);
                message.Append(str);
                message.Append("\n");
            }
            MessageBox.Show(message.ToString());

        }

        static void ParseString(string input)
        {
            StringBuilder num = new StringBuilder(input);
            num.Replace(" ", "");
            num.Replace(",", ".");
            double number = double.Parse(num.ToString());
            Console.WriteLine(number);
        }

        static string Encode(string input)
        {
            EncodingInfo[] infos = Encoding.GetEncodings();
            StringBuilder result = new StringBuilder("");
            foreach (EncodingInfo eInfo in infos)
            {
                byte[] bytes = Encoding.GetEncoding(eInfo.Name).GetBytes(input);
                foreach (byte b in bytes)
                {
                    result.Append(string.Format("\\x{0:X}", b));
                }
                result.Append("\n");
            }
            return result.ToString();
        }

        static string Decode(string bytes)
        {
            //TO DO
        }

        static void Main()
        {
            //PrintStringInHexBytes("Hi!");

            //PrintNumbers5to25();

            //Fraction fract = new Fraction(1, 3);
            //Console.WriteLine(fract);
            //Console.WriteLine(fract.ToString("N", null));
            //Console.WriteLine(fract.ToString("R", null));

            //ParseDate("13.11.2005");

            //PrintCurrencies(100.56);

            //ParseString("2 3 4.324");

            string bytes = Encode("Ivan");
            Console.WriteLine(bytes);
        }
    }
}
